<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<base href="/beadhouse/"/>  
<script src="about/js/jquery.min.js"></script>

<title>Insert title here</title>
</head>
<body>
<div class="col-md-9 pd0 fmt5">
				</div>			
				<div class="modal fade myModal1">
					<div class="modal-dialog">
						<div class="modal-content" style="width:100%;">
							<div class="modal-header">
								
								<span class="glyphicon glyphicon-pencil"></span>&nbsp;【入住登记】
							</div>
							
							
							<form
							     id="xiuGaiForm">
							        
								<input
						            type="hidden"
						            name="id">
						            
						            
							
							<div class="modal-body clearfix" style="height: auto;">
							
								<div class="col-md-12 pd0">
									<div class="col-md-1 pd0 mt10"></div>
									<div class="col-md-10 pd0">
										<div class="col-md-12 pd0">
											<div class="input-group inputWidth">
												<span class="input-group-addon titleWidth">&nbsp;&nbsp;客户姓名：</span>
												<input name="customerName" type="text" class="form-control" placeholder="请输入【客户姓名】信息">
											</div>
										</div>
									</div>
									<div class="col-md-1 pd0"></div>
								</div>
								<div class="col-md-12 pd0 mt10">
									<div class="col-md-1 pd0"></div>
									<div class="col-md-10 pd0">
										<div class="col-md-12 pd0">
											<div class="input-group inputWidth">
												<span class="input-group-addon titleWidth">&nbsp;&nbsp;年龄：</span>
												<input name="customerAge" type="text" class="form-control" placeholder="请输入【年龄】信息">
											</div>
										</div>
									</div>
									<div class="col-md-1 pd0"></div>
								</div>
								<div class="col-md-12 pd0 mt10">
									<div class="col-md-1 pd0"></div>
									<div class="col-md-10 pd0">
										<div class="col-md-12 pd0">
											<div class="input-group inputWidth">
												<span class="input-group-addon titleWidth">&nbsp;&nbsp;性别：</span>
												<select name="customerSex" class="form-control" >
													<option>男</option>
													<option>女</option>
													
												</select>
											</div>
										</div>
									</div>
									<div class="col-md-1 pd0"></div>
								</div>
								<div class="col-md-12 pd0 mt10">
									<div class="col-md-1 pd0"></div>
									<div class="col-md-10 pd0">
										<div class="col-md-12 pd0">
											<div class="input-group inputWidth">
												<span class="input-group-addon titleWidth">&nbsp;&nbsp;身份证号：</span>
												<input  name="idcard" type="text" class="form-control" placeholder="请输入【身份证号】信息">
											</div>
										</div>
									</div>
									<div class="col-md-1 pd0"></div>
								</div>
								<div class="col-md-12 pd0 mt10">
									<div class="col-md-1 pd0"></div>
									<div class="col-md-10 pd0">
										<div class="col-md-12 pd0">
											<div class="input-group inputWidth">
												<span class="input-group-addon titleWidth">&nbsp;&nbsp;房间号：</span>
												<input name="roomNumber" type="text" class="form-control" placeholder="请输入【房间号】信息">
											</div>
										</div>
									</div>
									<div class="col-md-1 pd0"></div>
								</div>
								
								<div class="col-md-12 pd0 mt10">
									<div class="col-md-1 pd0"></div>
									<div class="col-md-10 pd0">
										<div class="col-md-12 pd0">
											<div class="input-group inputWidth">
												<span class="input-group-addon titleWidth">&nbsp;&nbsp;档案号：</span>
												<input name="recordId" type="text" class="form-control" placeholder="请输入【档案号】信息">
											</div>
										</div>
									</div>
									<div class="col-md-1 pd0"></div>
								</div>
								
								<div class="col-md-12 pd0 mt10">
									<div class="col-md-1 pd0"></div>
									<div class="col-md-10 pd0">
										<div class="col-md-12 pd0">
											<div class="input-group inputWidth">
												<span class="input-group-addon titleWidth">&nbsp;&nbsp;入住时间：</span>
												<input name="checkinDate" type="date" class="form-control">
											</div>
										</div>
									</div>
									<div class="col-md-1 pd0"></div>
								</div>
								<div class="col-md-12 pd0 mt10">
									<div class="col-md-1 pd0"></div>
									<div class="col-md-10 pd0">
										<div class="col-md-12 pd0">
											<div class="input-group inputWidth">
												<span class="input-group-addon titleWidth">&nbsp;&nbsp;合同到期时间：</span>
												<input name="expirationDate" type="date" class="form-control">
											</div>
										</div>
									</div>
									<div class="col-md-1 pd0"></div>
								</div>
								<div class="col-md-12 pd0 mt10">
									<div class="col-md-1 pd0"></div>
									<div class="col-md-10 pd0">
										<div class="col-md-12 pd0">
											<div class="input-group inputWidth">
												<span class="input-group-addon titleWidth">&nbsp;&nbsp;联系电话：</span>
												<input  name="contactTel" type="text" class="form-control" placeholder="请输入【联系电话】信息">
											</div>
										</div>
									</div>
									<div class="col-md-1 pd0"></div>
								</div>
								
								<div class="col-md-12 pd0 mt10">
									<div class="col-md-1 pd0"></div>
									<div class="col-md-10 pd0">
										<div class="col-md-12 pd0">
											<div class="input-group inputWidth">
												<span class="input-group-addon titleWidth">&nbsp;&nbsp;备注：</span>
												<input name="remark" type="text" class="form-control" aria-describedby="basic-addon1">
											</div>
										</div>
									</div>
									<div class="col-md-1 pd0"></div>
								</div>
								
							</div>
							</form>
							<div class="modal-footer mt20">
								<button id="updateBtn" type="button"  class="btn btn-primary" data-dismiss="modal">
									确定
								</button>
								<button  type="button" class="btn btn-default" data-dismiss="modal">
									取消
								</button>
							</div>
						</div>
					</div>
				</div>
</body>

<script type="text/javascript">
(function() {
	"use strict";
	var id;
	var $xiuGaiForm;
	var $updateBtn;


	$(function() {
		id=window.location.hash.substr(1);
		console.log(id);
		$xiuGaiForm=$("#xiuGaiForm");
		$updateBtn=$("#updateBtn");
		$updateBtn.click(handleUpdateBtnClick);
		loadModel(id);

	});
	
	
	//查一列:id
	var loadModel=function(id){
		var url="/beadhouse/api/customer/selectCustomer?id="+id;
		$.get(url,function(resp){
			console.log(resp);
			if(resp.code==="ok"){
				paintView(resp.data);
			}else{
				alert(resp.message);
			}
		})
		
	};

	//修改
	window.handleUpdateBtnClick = function() {

		var url = "/beadhouse/api/customer/update";
		
		$.get(url,$xiuGaiForm.serialize(),function(resp) {

			if (resp.code === "ok") {
				
				console.log(resp);
				alert("修改成功");
				location.href="page/rzdj.html";
				
			} else {
				alert(resp.message);
			}
		})
	};

	var paintView=function(m){
		var form=$xiuGaiForm[0];
		form.id.value=m.id;
		form.customerName.value=m.customerName;
		form.customerAge.value=m.customerAge;
		if(m.customerSex){
			form.customerSex.value="男";
		}else{
			form.customerSex.value="女";
		}
		
		
		form.roomNumber.value=m.roomNumber;
		form.idcard.value=m.idcard;
		form.recordId.value=m.recordId;
		form.checkinDate.value=formatDate(m.checkinDate);
		form.expirationDate.value=formatDate(m.expirationDate);
		form.contactTel.value=m.contactTel;
		form.remark.value=m.remark;
		
	}
	//日期转换
	var formatDate =function(date){
		date = new Date(date);
        var y=getzf(date.getFullYear());//年
        var m=getzf(date.getMonth()+1);//月	
        var d=getzf(date.getDate());//日
     
        var result=y+'-'+m+'-'+d;
        return result;
     
    }
	var getzf=function(num){  
        if(num < 10){  
            num = '0'+num;  
        }  
        return num;  
	}
})();
</script>


</html>